package com.myapp.web.struts2.multipart;

public class FileItemProgressInfo {
	
	private String fileName;
	private long totalSize  = 0;
	private long lastBytesRead = 0;
	private long bytesRead  = 0;
	private int  fileIndex  = 0;
	private long startTime  = System.currentTimeMillis();
	private long accessTime = System.currentTimeMillis();
	
	private String errorMsg ;
	
	public FileItemProgressInfo(){		
	}
	public FileItemProgressInfo(int index,String name,long size){
		fileIndex = index ;
		fileName = name;
		totalSize = size;
	}
	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public long getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
	}

	public long getBytesRead() {
		return bytesRead;
	}

	public void setBytesRead(long bytesRead) {
		lastBytesRead = this.bytesRead;
		this.bytesRead = bytesRead;		
	}

	public boolean isPeriod(){
		if(totalSize > 0 && (float)(bytesRead - lastBytesRead) / totalSize * 100.00f > 10f ){
			lastBytesRead = bytesRead;
			return true;
		}
		if(System.currentTimeMillis() - accessTime > 1000L){
			accessTime = System.currentTimeMillis();
			return true;
		}
		return false;
	}
	public long getDeltaTime() {
		return accessTime - System.currentTimeMillis();
	}

	public int getFileIndex() {
		return fileIndex;
	}

	public void setFileIndex(int fileIndex) {
		this.fileIndex = fileIndex;
	}

	public boolean isCompleted() {
		return bytesRead == totalSize ? true : false;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
}
